var express = require('express');
var path = require('path');
var md5 = require('md5');
var router = express.Router();
var User = require('../models/users');

router.get('/', function(req, res, next) {
	console.log(req.session)//打印session的值
	if (req.session.sign) {//检查用户是否已经登录
        console.log(req.session);
        User.update({username:req.body.username},{password:req.body.password},function(err,raw){
            res.send({
                state:1,
                msg:"修改成功"
            })
            
        })
  } 
})

router.post('/', function(req, res, next) {
	console.log(global.name)
	if (req.session.sign) {//检查用户是否已经登录
        // console.log(req.session);//打印session的值
        var modifyPwd = md5(req.body.password)
        console.log(modifyPwd)
        User.update({username:req.session.name},{password:modifyPwd},function(err,raw){
            res.send({
                state:1,
                msg:"修改成功"
            })
            
        })
  }else{
    res.send({
        state:0,
        msg:"请先登录再修改"
    })
  } 
})
module.exports = router;
